let fs = require('fs')
let path = require('path')
let router = require('express').Router()
let multer = require('multer')
// 设置临时文件存放文件夹
router.use(multer({ dest: '../upload/' }).any())

router.post('/', async (req, res, next) => {
    let file = req.files[0]
    let newPath = path.join(__dirname, '../upload', file.originalname)
    fs.rename(file.path, newPath, _=>{})
    res.success('上传成功！', {
        filePath: 'http://localhost:80' + '/upload/' + file.originalname,
        fileName: file.originalname
    })
})

module.exports = router